﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DataCentral.Dataset;
using DataCentral.Dataset.DataCentralDatasetTableAdapters;

namespace DataCentral.UserControls
{
    public partial class EditSaleOrderDetailControl : DataCentral.CommonCenterControl
    {
        public EditSaleOrderDetailControl()
        {
            InitializeComponent();
        }

        private void StandardizationData()
        {
            SlsOrdDspTableAdapter daSlsOrder = new SlsOrdDspTableAdapter();
            daSlsOrder.Fill(dsCentral.SlsOrdDsp, dtpFromDate.DateTime, dtpToDate.DateTime);
            foreach (DataCentralDataset.DspOrdDetRow drSaleOrderDetail in dsCentral.DspOrdDet)
            {
                if (drSaleOrderDetail.IsDspOrdIDNull())
                {
                    DataRow [] lstOrders = dsCentral.SlsOrdDsp.Select(string.Format("OrderNbr = '{0}'",drSaleOrderDetail.OrderNbr));
                    if (lstOrders.Length > 0)
                    {
                        drSaleOrderDetail.DspOrdID = Convert.ToDecimal(lstOrders[0]["SlsOrdDspID"].ToString());
                    }
                }
            }
        }

        private void EditSaleOrderDetail_Load(object sender, EventArgs e)
        {
            dtpFromDate.DateTime = DateTime.Now;
            dtpToDate.DateTime = DateTime.Now;
            daSaleOrderDetail.Fill(dsCentral.DspOrdDet, dtpFromDate.DateTime.Date, dtpToDate.DateTime.Date);
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            daSaleOrderDetail.Fill(dsCentral.DspOrdDet, dtpFromDate.DateTime.Date, dtpToDate.DateTime.Date);
        }

        private void btnStandardization_Click(object sender, EventArgs e)
        {
            StandardizationData();
            daSaleOrderDetail.Update(dsCentral.DspOrdDet);
        }
    }
}
